/**
 * @author: p_haojiawu@tencent.com
 * @date: 2023-01-06 11:16
 **/
package com.tencent.qf.common.util;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

@Slf4j
public class SHA1Util {
    public static String getHmacSHA1(String rawString,String appsecret){
        try {
            Mac sha256_HMAC = Mac.getInstance("HmacSHA1");
            SecretKeySpec secret_key = new SecretKeySpec(appsecret.getBytes(), "HmacSHA1");
            sha256_HMAC.init(secret_key);

            return Base64.encodeBase64String(sha256_HMAC.doFinal(rawString.getBytes()));
        }
        catch (Exception e){
            e.printStackTrace();
            log.error("SHA256加密失败： " + e.getMessage());
            return "";
        }
    }
}
